



package jnpf.controller;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import jnpf.annotation.JnpfField;
import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.base.vo.PaginationVO;
import jnpf.base.UserInfo;
import jnpf.base.vo.DownloadVO;
import jnpf.config.ConfigValueUtil;
import jnpf.exception.DataException;
import jnpf.onlinedev.model.ExcelImFieldModel;
import jnpf.onlinedev.model.OnlineImport.ExcelImportModel;
import jnpf.onlinedev.model.OnlineImport.VisualImportModel;
import jnpf.permission.entity.UserEntity;
import org.springframework.transaction.annotation.Transactional;
import jnpf.base.entity.ProvinceEntity;
import jnpf.model.mzfileconfiguration.*;
import jnpf.model.mzfileconfiguration.MzFileconfigurationPagination;
import jnpf.entity.*;
import jnpf.util.*;
import jnpf.base.util.*;
import jnpf.base.vo.ListVO;
import jnpf.util.context.SpringContext;
import cn.hutool.core.util.ObjectUtil;
import lombok.extern.slf4j.Slf4j;
import lombok.Cleanup;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import jnpf.entity.MzFileconfigurationEntity;
import jnpf.service.MzFileconfigurationService;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.Valid;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import jnpf.util.GeneraterSwapUtil;
import java.util.stream.Collectors;
import java.util.*;

import cn.xuyanwu.spring.file.storage.FileInfo;


/**
 *
 * mzFileconfiguration
 * @版本： V3.2.0
 * @版权： 引迈信息技术有限公司（https://www.jnpfsoft.com）
 * @作者： JNPF开发平台组
 * @日期： 2023-12-08
 */
@Slf4j
@RestController
@Tag(name = "mzFileconfiguration" , description = "example")
@RequestMapping("/api/example/MzFileconfiguration")
public class MzFileconfigurationController {

    @Autowired
    private GeneraterSwapUtil generaterSwapUtil;


    @Autowired
    private UserProvider userProvider;


    @Autowired
    private MzFileconfigurationService mzFileconfigurationService;



    /**
     * 列表
     *
     * @param mzFileconfigurationPagination
     * @return
     */
    @Operation(summary = "获取列表")
	@PostMapping("/getList")
    public ActionResult list(@RequestBody MzFileconfigurationPagination mzFileconfigurationPagination)throws IOException{
    //树形判断是否有参数，有参数不造树
        List<MzFileconfigurationEntity> list= mzFileconfigurationService.getList(mzFileconfigurationPagination);
        //处理id字段转名称，若无需转或者为空可删除

    List<MzFileconfigurationListVO> listVO=JsonUtil.getJsonToList(list,MzFileconfigurationListVO.class);
    for(MzFileconfigurationListVO mzFileconfigurationVO:listVO){
        ActionResult info = info(mzFileconfigurationVO.getId());
        Map<String, Object> dataMap = JsonUtil.entityToMap(info.getData());
            mzFileconfigurationVO.setPicturefiles_name(generaterSwapUtil.getDicName(mzFileconfigurationVO.getPicturefiles(),"502822474723885061"));

                mzFileconfigurationVO.setPicturefilessize_name(generaterSwapUtil.getDecimalStr(mzFileconfigurationVO.getPicturefilessize()));

            mzFileconfigurationVO.setVideofile_name(generaterSwapUtil.getDicName(mzFileconfigurationVO.getVideofile(),"502823022948777989"));

                mzFileconfigurationVO.setVideofilesize_name(generaterSwapUtil.getDecimalStr(mzFileconfigurationVO.getVideofilesize()));

            mzFileconfigurationVO.setOfficedocuments_name(generaterSwapUtil.getDicName(mzFileconfigurationVO.getOfficedocuments(),"502823186329501701"));

                mzFileconfigurationVO.setOfficedocumentssize_name(generaterSwapUtil.getDecimalStr(mzFileconfigurationVO.getOfficedocumentssize()));

            mzFileconfigurationVO.setCompressedfile_name(generaterSwapUtil.getDicName(mzFileconfigurationVO.getCompressedfile(),"502830609077370885"));

                mzFileconfigurationVO.setCompressedfilesize_name(generaterSwapUtil.getDecimalStr(mzFileconfigurationVO.getCompressedfilesize()));

		//子表数据转换
     }

         PageListVO vo=new PageListVO();
         vo.setList(listVO);
         PaginationVO page=JsonUtil.getJsonToBean(mzFileconfigurationPagination,PaginationVO.class);
         vo.setPagination(page);
         return ActionResult.success(vo);

    }

    /**
     * 创建
     *
     * @param mzFileconfigurationForm
     * @return
     */
    @PostMapping
    @Transactional
    @Operation(summary = "创建")
    public ActionResult create(@RequestBody @Valid MzFileconfigurationForm mzFileconfigurationForm) throws DataException {
        String b = mzFileconfigurationService.checkForm(mzFileconfigurationForm,0);
        if (StringUtil.isNotEmpty(b)){
         return ActionResult.fail(b + "不能重复");
        }
        String mainId =RandomUtil.uuId();

        UserInfo userInfo=userProvider.get();
		UserEntity userEntity = generaterSwapUtil.getUser(userInfo.getUserId());
        GeneraterSwapUtil.swapDatetime(mzFileconfigurationForm);
        MzFileconfigurationEntity entity = JsonUtil.getJsonToBean(mzFileconfigurationForm, MzFileconfigurationEntity.class);
            entity.setId(mainId);
                mzFileconfigurationService.save(entity);


        return ActionResult.success("创建成功");
}


    /**
    * 信息
    *
    * @param id
    * @return
    */
    @Operation(summary = "信息")
    @GetMapping("/{id}")
    public ActionResult<MzFileconfigurationInfoVO> info(@PathVariable("id") String id){
        MzFileconfigurationEntity entity= mzFileconfigurationService.getInfo(id);
        MzFileconfigurationInfoVO vo=JsonUtil.getJsonToBean(entity, MzFileconfigurationInfoVO.class);

    //子表
    //副表
        return ActionResult.success(vo);
    }

    /**
    * 表单信息(详情页)
    *
    * @param id
    * @return
    */
    @Operation(summary = "表单信息(详情页)")
    @GetMapping("/detail/{id}")
    public ActionResult<MzFileconfigurationInfoVO> detailInfo(@PathVariable("id") String id){
        ActionResult info = info(id);
        Map<String,Object> dataMap = JsonUtil.entityToMap(info.getData());
        MzFileconfigurationEntity entity= mzFileconfigurationService.getInfo(id);
        MzFileconfigurationInfoVO vo=JsonUtil.getJsonToBean(entity, MzFileconfigurationInfoVO.class);

 //子表数据转换

 //附表数据转换

//添加到详情表单对象中
            vo.setPicturefiles(generaterSwapUtil.getDicName(vo.getPicturefiles(),"502822474723885061"));

                vo.setPicturefilessize_name(generaterSwapUtil.getDecimalStr(vo.getPicturefilessize()));

            vo.setVideofile(generaterSwapUtil.getDicName(vo.getVideofile(),"502823022948777989"));

                vo.setVideofilesize_name(generaterSwapUtil.getDecimalStr(vo.getVideofilesize()));

            vo.setOfficedocuments(generaterSwapUtil.getDicName(vo.getOfficedocuments(),"502823186329501701"));

                vo.setOfficedocumentssize_name(generaterSwapUtil.getDecimalStr(vo.getOfficedocumentssize()));

            vo.setCompressedfile(generaterSwapUtil.getDicName(vo.getCompressedfile(),"502830609077370885"));

                vo.setCompressedfilesize_name(generaterSwapUtil.getDecimalStr(vo.getCompressedfilesize()));


        return ActionResult.success(vo);
		}




   /**
    * 更新
    *
    * @param id
    * @param mzFileconfigurationForm
    * @return
    */
    @PutMapping("/{id}")
    @Transactional
    @Operation(summary = "更新")
    public ActionResult update(@PathVariable("id") String id,@RequestBody @Valid MzFileconfigurationForm mzFileconfigurationForm) throws DataException {
        String b =  mzFileconfigurationService.checkForm(mzFileconfigurationForm,1);
        if (StringUtil.isNotEmpty(b)){
            return ActionResult.fail(b + "不能重复");
        }
        UserInfo userInfo=userProvider.get();
        MzFileconfigurationEntity entity= mzFileconfigurationService.getInfo(id);
        if(entity!=null){
            GeneraterSwapUtil.swapDatetime(mzFileconfigurationForm);
            MzFileconfigurationEntity subentity=JsonUtil.getJsonToBean(mzFileconfigurationForm, MzFileconfigurationEntity.class);
				boolean b1 = mzFileconfigurationService.updateById(subentity);
				if (!b1){
				return ActionResult.fail("当前表单原数据已被调整，请重新进入该页面编辑并提交数据");
				}
        return ActionResult.success("更新成功");
        }else{
            return ActionResult.fail("更新失败，数据不存在");
        }
    }



   /**
    * 删除
    *
    * @param id
    * @return
    */
    @Operation(summary = "删除")
    @DeleteMapping("/{id}")
    @Transactional
    public ActionResult delete(@PathVariable("id") String id){
        MzFileconfigurationEntity entity= mzFileconfigurationService.getInfo(id);
        if(entity!=null){
            mzFileconfigurationService.delete(entity);
        }
        return ActionResult.success("删除成功");
    }











}
